/* QtLua -- Lua bindings for Qt
   Copyright (C) 2011, Jarek Pelczar

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301 USA

*/

#ifndef QDATETIME_PROTOTYPE_H
#define QDATETIME_PROTOTYPE_H

#include <QObject>
#include <QDateTime>
#include "qluascriptable.h"
#include "qluascriptengine.h"
#include "qluascriptvalue.h"
#include "qluascriptclass.h"
#include "qluaglobal.h"

class QDateTime_prototype : public QObject, public QLuaScriptable
{
    Q_OBJECT
    Q_INTERFACES(QLuaScriptable)
public:
    explicit QDateTime_prototype(QObject *parent = 0);

public slots:
    bool isNull() const;
    bool isValid() const;
    QString toString() const;
    QDateTime addDays(int ndays) const;
    QDateTime addMSecs(qint64 msecs) const;
    QDateTime addMonths(int nmonths) const;
    QDateTime addSecs(int s) const;
    QDateTime addYears(int nyears) const;
    int daysTo(const QDateTime &) const;
    int secsTo(const QDateTime &) const;
    qint64 msecsTo(const QDateTime &) const;
    qint64 toMSecsSinceEpoch() const;

private:
    QDateTime * ptr() const;
};

class QDateTime_wrapper : public QObject, public QLuaScriptClass
{
    Q_OBJECT
    Q_INTERFACES(QLuaScriptClass)
public:
    explicit QDateTime_wrapper(QLuaScriptEngine * engine);

    virtual QueryFlags queryProperty(const QLuaScriptValue& object,
                                     const QByteArray& name);
    virtual QLuaScriptValue property(const QLuaScriptValue& object,
                                          const QByteArray& name);
    virtual void setProperty(const QLuaScriptValue& object,
                             const QByteArray& name,
                             const QLuaScriptValue& value);
    virtual QLuaScriptValue prototype() const;
    virtual QString name() const;

private:
    static QLuaScriptValue new_obj(QLuaScriptContext *, QLuaScriptEngine *);
    static QLuaScriptValue new_current(QLuaScriptContext *, QLuaScriptEngine *);
    static QLuaScriptValue new_currentUtc(QLuaScriptContext *, QLuaScriptEngine *);

    static QLuaScriptValue QDateTime_toScriptValue(QLuaScriptEngine * engine, const QDateTime * t);
    static void QDateTime_fromScriptValue(const QLuaScriptValue& value, QDateTime * t);
private:
    QLuaScriptValue m_proto;
};

#endif // QDATETIME_PROTOTYPE_H
